#include "PrecompiledHeaderRenderer_OpenGL.h"
#include "CommonWrapper.h"

/*--------------------------------------------------------------------------*/
glm::ivec4 CommonWrapper::_colorMask = glm::ivec4(1, 1, 1, 1);
glm::vec4 CommonWrapper::_viewport = glm::vec4(0, 0, 800, 600);

GLVertexArray* CommonWrapper::_fullscreenQuadVao = NULL;
GLVertexArray* CommonWrapper::_primitiveContainerVao = NULL;
GLVertexBuffer* CommonWrapper::_primitiveContainer = NULL;

GLVertexArray* CommonWrapper::_cubeVao = NULL;
GLVertexArray* CommonWrapper::_largeSphereVao = NULL;
GLVertexArray* CommonWrapper::_smallSphereVao = NULL;
GLVertexArray* CommonWrapper::_quadVao = NULL;

/*--------------------------------------------------------------------------*/

CommonWrapper::CommonWrapper()
{
	glColorMask(_colorMask.r == 1, _colorMask.g == 1, _colorMask.b == 1, _colorMask.a == 1);
	glViewport(_viewport.x, _viewport.y, _viewport.z, _viewport.w);
}

/*--------------------------------------------------------------------------*/

CommonWrapper::~CommonWrapper()
{

}

/*--------------------------------------------------------------------------*/

GLenum CommonWrapper::GetError()
{
	return glGetError();
}

/*--------------------------------------------------------------------------*/

GLenum CommonWrapper::StrToEnum(const std::string& c)
{
	//http://www.gamedev.net/topic/371162-enum---from-string-to-glenum/

	static std::map<const std::string, int> retVal = std::map<const std::string, int>();
	static bool initialized = false;

	if (initialized == false)
	{
		initialized = true;

		retVal["GL_VERSION_1_1"] = 1;
		retVal["GL_VERSION_1_2"] = 1;
		retVal["GL_VERSION_1_3"] = 1;
		retVal["GL_ARB_imaging"] = 1;
		retVal["GL_FALSE"] = 0x0;
		retVal["GL_TRUE"] = 0x1;
		retVal["GL_BYTE"] = 0x1400;
		retVal["GL_UNSIGNED_BYTE"] = 0x1401;
		retVal["GL_SHORT"] = 0x1402;
		retVal["GL_UNSIGNED_SHORT"] = 0x1403;
		retVal["GL_INT"] = 0x1404;
		retVal["GL_UNSIGNED_INT"] = 0x1405;
		retVal["GL_FLOAT"] = 0x1406;
		retVal["GL_DOUBLE"] = 0x140A;
		retVal["GL_2_BYTES"] = 0x1407;
		retVal["GL_3_BYTES"] = 0x1408;
		retVal["GL_4_BYTES"] = 0x1409;
		retVal["GL_POINTS"] = 0x0000;
		retVal["GL_LINES"] = 0x0001;
		retVal["GL_LINE_LOOP"] = 0x0002;
		retVal["GL_LINE_STRIP"] = 0x0003;
		retVal["GL_TRIANGLES"] = 0x0004;
		retVal["GL_TRIANGLE_STRIP"] = 0x0005;
		retVal["GL_TRIANGLE_FAN"] = 0x0006;
		retVal["GL_QUADS"] = 0x0007;
		retVal["GL_QUAD_STRIP"] = 0x0008;
		retVal["GL_POLYGON"] = 0x0009;
		retVal["GL_VERTEX_ARRAY"] = 0x8074;
		retVal["GL_NORMAL_ARRAY"] = 0x8075;
		retVal["GL_COLOR_ARRAY"] = 0x8076;
		retVal["GL_INDEX_ARRAY"] = 0x8077;
		retVal["GL_TEXTURE_COORD_ARRAY"] = 0x8078;
		retVal["GL_EDGE_FLAG_ARRAY"] = 0x8079;
		retVal["GL_VERTEX_ARRAY_SIZE"] = 0x807A;
		retVal["GL_VERTEX_ARRAY_TYPE"] = 0x807B;
		retVal["GL_VERTEX_ARRAY_STRIDE"] = 0x807C;
		retVal["GL_NORMAL_ARRAY_TYPE"] = 0x807E;
		retVal["GL_NORMAL_ARRAY_STRIDE"] = 0x807F;
		retVal["GL_COLOR_ARRAY_SIZE"] = 0x8081;
		retVal["GL_COLOR_ARRAY_TYPE"] = 0x8082;
		retVal["GL_COLOR_ARRAY_STRIDE"] = 0x8083;
		retVal["GL_INDEX_ARRAY_TYPE"] = 0x8085;
		retVal["GL_INDEX_ARRAY_STRIDE"] = 0x8086;
		retVal["GL_TEXTURE_COORD_ARRAY_SIZE"] = 0x8088;
		retVal["GL_TEXTURE_COORD_ARRAY_TYPE"] = 0x8089;
		retVal["GL_TEXTURE_COORD_ARRAY_STRIDE"] = 0x808A;
		retVal["GL_EDGE_FLAG_ARRAY_STRIDE"] = 0x808C;
		retVal["GL_VERTEX_ARRAY_POINTER"] = 0x808E;
		retVal["GL_NORMAL_ARRAY_POINTER"] = 0x808F;
		retVal["GL_COLOR_ARRAY_POINTER"] = 0x8090;
		retVal["GL_INDEX_ARRAY_POINTER"] = 0x8091;
		retVal["GL_TEXTURE_COORD_ARRAY_POINTER"] = 0x8092;
		retVal["GL_EDGE_FLAG_ARRAY_POINTER"] = 0x8093;
		retVal["GL_V2F"] = 0x2A20;
		retVal["GL_V3F"] = 0x2A21;
		retVal["GL_C4UB_V2F"] = 0x2A22;
		retVal["GL_C4UB_V3F"] = 0x2A23;
		retVal["GL_C3F_V3F"] = 0x2A24;
		retVal["GL_N3F_V3F"] = 0x2A25;
		retVal["GL_C4F_N3F_V3F"] = 0x2A26;
		retVal["GL_T2F_V3F"] = 0x2A27;
		retVal["GL_T4F_V4F"] = 0x2A28;
		retVal["GL_T2F_C4UB_V3F"] = 0x2A29;
		retVal["GL_T2F_C3F_V3F"] = 0x2A2A;
		retVal["GL_T2F_N3F_V3F"] = 0x2A2B;
		retVal["GL_T2F_C4F_N3F_V3F"] = 0x2A2C;
		retVal["GL_T4F_C4F_N3F_V4F"] = 0x2A2D;
		retVal["GL_MATRIX_MODE"] = 0x0BA0;
		retVal["GL_MODELVIEW"] = 0x1700;
		retVal["GL_PROJECTION"] = 0x1701;
		retVal["GL_TEXTURE"] = 0x1702;
		retVal["GL_POINT_SMOOTH"] = 0x0B10;
		retVal["GL_POINT_SIZE"] = 0x0B11;
		retVal["GL_POINT_SIZE_GRANULARITY"] = 0x0B13;
		retVal["GL_POINT_SIZE_RANGE"] = 0x0B12;
		retVal["GL_LINE_SMOOTH"] = 0x0B20;
		retVal["GL_LINE_STIPPLE"] = 0x0B24;
		retVal["GL_LINE_STIPPLE_PATTERN"] = 0x0B25;
		retVal["GL_LINE_STIPPLE_REPEAT"] = 0x0B26;
		retVal["GL_LINE_WIDTH"] = 0x0B21;
		retVal["GL_LINE_WIDTH_GRANULARITY"] = 0x0B23;
		retVal["GL_LINE_WIDTH_RANGE"] = 0x0B22;
		retVal["GL_POINT"] = 0x1B00;
		retVal["GL_LINE"] = 0x1B01;
		retVal["GL_FILL"] = 0x1B02;
		retVal["GL_CW"] = 0x0900;
		retVal["GL_CCW"] = 0x0901;
		retVal["GL_FRONT"] = 0x0404;
		retVal["GL_BACK"] = 0x0405;
		retVal["GL_POLYGON_MODE"] = 0x0B40;
		retVal["GL_POLYGON_SMOOTH"] = 0x0B41;
		retVal["GL_POLYGON_STIPPLE"] = 0x0B42;
		retVal["GL_EDGE_FLAG"] = 0x0B43;
		retVal["GL_CULL_FACE"] = 0x0B44;
		retVal["GL_CULL_FACE_MODE"] = 0x0B45;
		retVal["GL_FRONT_FACE"] = 0x0B46;
		retVal["GL_POLYGON_OFFSET_FACTOR"] = 0x8038;
		retVal["GL_POLYGON_OFFSET_UNITS"] = 0x2A00;
		retVal["GL_POLYGON_OFFSET_POINT"] = 0x2A01;
		retVal["GL_POLYGON_OFFSET_LINE"] = 0x2A02;
		retVal["GL_POLYGON_OFFSET_FILL"] = 0x8037;
		retVal["GL_COMPILE"] = 0x1300;
		retVal["GL_COMPILE_AND_EXECUTE"] = 0x1301;
		retVal["GL_LIST_BASE"] = 0x0B32;
		retVal["GL_LIST_INDEX"] = 0x0B33;
		retVal["GL_LIST_MODE"] = 0x0B30;
		retVal["GL_NEVER"] = 0x0200;
		retVal["GL_LESS"] = 0x0201;
		retVal["GL_EQUAL"] = 0x0202;
		retVal["GL_LEQUAL"] = 0x0203;
		retVal["GL_GREATER"] = 0x0204;
		retVal["GL_NOTEQUAL"] = 0x0205;
		retVal["GL_GEQUAL"] = 0x0206;
		retVal["GL_ALWAYS"] = 0x0207;
		retVal["GL_DEPTH_TEST"] = 0x0B71;
		retVal["GL_DEPTH_BITS"] = 0x0D56;
		retVal["GL_DEPTH_CLEAR_VALUE"] = 0x0B73;
		retVal["GL_DEPTH_FUNC"] = 0x0B74;
		retVal["GL_DEPTH_RANGE"] = 0x0B70;
		retVal["GL_DEPTH_WRITEMASK"] = 0x0B72;
		retVal["GL_DEPTH_COMPONENT"] = 0x1902;
		retVal["GL_LIGHTING"] = 0x0B50;
		retVal["GL_LIGHT0"] = 0x4000;
		retVal["GL_LIGHT1"] = 0x4001;
		retVal["GL_LIGHT2"] = 0x4002;
		retVal["GL_LIGHT3"] = 0x4003;
		retVal["GL_LIGHT4"] = 0x4004;
		retVal["GL_LIGHT5"] = 0x4005;
		retVal["GL_LIGHT6"] = 0x4006;
		retVal["GL_LIGHT7"] = 0x4007;
		retVal["GL_SPOT_EXPONENT"] = 0x1205;
		retVal["GL_SPOT_CUTOFF"] = 0x1206;
		retVal["GL_CONSTANT_ATTENUATION"] = 0x1207;
		retVal["GL_LINEAR_ATTENUATION"] = 0x1208;
		retVal["GL_QUADRATIC_ATTENUATION"] = 0x1209;
		retVal["GL_AMBIENT"] = 0x1200;
		retVal["GL_DIFFUSE"] = 0x1201;
		retVal["GL_SPECULAR"] = 0x1202;
		retVal["GL_SHININESS"] = 0x1601;
		retVal["GL_EMISSION"] = 0x1600;
		retVal["GL_POSITION"] = 0x1203;
		retVal["GL_SPOT_DIRECTION"] = 0x1204;
		retVal["GL_AMBIENT_AND_DIFFUSE"] = 0x1602;
		retVal["GL_COLOR_INDEXES"] = 0x1603;
		retVal["GL_LIGHT_MODEL_TWO_SIDE"] = 0x0B52;
		retVal["GL_LIGHT_MODEL_LOCAL_VIEWER"] = 0x0B51;
		retVal["GL_LIGHT_MODEL_AMBIENT"] = 0x0B53;
		retVal["GL_FRONT_AND_BACK"] = 0x0408;
		retVal["GL_SHADE_MODEL"] = 0x0B54;
		retVal["GL_FLAT"] = 0x1D00;
		retVal["GL_SMOOTH"] = 0x1D01;
		retVal["GL_COLOR_MATERIAL"] = 0x0B57;
		retVal["GL_COLOR_MATERIAL_FACE"] = 0x0B55;
		retVal["GL_COLOR_MATERIAL_PARAMETER"] = 0x0B56;
		retVal["GL_NORMALIZE"] = 0x0BA1;
		retVal["GL_CLIP_PLANE0"] = 0x3000;
		retVal["GL_CLIP_PLANE1"] = 0x3001;
		retVal["GL_CLIP_PLANE2"] = 0x3002;
		retVal["GL_CLIP_PLANE3"] = 0x3003;
		retVal["GL_CLIP_PLANE4"] = 0x3004;
		retVal["GL_CLIP_PLANE5"] = 0x3005;
		retVal["GL_ACCUM_RED_BITS"] = 0x0D58;
		retVal["GL_ACCUM_GREEN_BITS"] = 0x0D59;
		retVal["GL_ACCUM_BLUE_BITS"] = 0x0D5A;
		retVal["GL_ACCUM_ALPHA_BITS"] = 0x0D5B;
		retVal["GL_ACCUM_CLEAR_VALUE"] = 0x0B80;
		retVal["GL_ACCUM"] = 0x0100;
		retVal["GL_ADD"] = 0x0104;
		retVal["GL_LOAD"] = 0x0101;
		retVal["GL_MULT"] = 0x0103;
		retVal["GL_RETURN"] = 0x0102;
		retVal["GL_ALPHA_TEST"] = 0x0BC0;
		retVal["GL_ALPHA_TEST_REF"] = 0x0BC2;
		retVal["GL_ALPHA_TEST_FUNC"] = 0x0BC1;
		retVal["GL_BLEND"] = 0x0BE2;
		retVal["GL_BLEND_SRC"] = 0x0BE1;
		retVal["GL_BLEND_DST"] = 0x0BE0;
		retVal["GL_ZERO"] = 0x0;
		retVal["GL_ONE"] = 0x1;
		retVal["GL_SRC_COLOR"] = 0x0300;
		retVal["GL_ONE_MINUS_SRC_COLOR"] = 0x0301;
		retVal["GL_SRC_ALPHA"] = 0x0302;
		retVal["GL_ONE_MINUS_SRC_ALPHA"] = 0x0303;
		retVal["GL_DST_ALPHA"] = 0x0304;
		retVal["GL_ONE_MINUS_DST_ALPHA"] = 0x0305;
		retVal["GL_DST_COLOR"] = 0x0306;
		retVal["GL_ONE_MINUS_DST_COLOR"] = 0x0307;
		retVal["GL_SRC_ALPHA_SATURATE"] = 0x0308;
		retVal["GL_CONSTANT_COLOR"] = 0x8001;
		retVal["GL_ONE_MINUS_CONSTANT_COLOR"] = 0x8002;
		retVal["GL_CONSTANT_ALPHA"] = 0x8003;
		retVal["GL_ONE_MINUS_CONSTANT_ALPHA"] = 0x8004;
		retVal["GL_FEEDBACK"] = 0x1C01;
		retVal["GL_RENDER"] = 0x1C00;
		retVal["GL_SELECT"] = 0x1C02;
		retVal["GL_2D"] = 0x0600;
		retVal["GL_3D"] = 0x0601;
		retVal["GL_3D_COLOR"] = 0x0602;
		retVal["GL_3D_COLOR_TEXTURE"] = 0x0603;
		retVal["GL_4D_COLOR_TEXTURE"] = 0x0604;
		retVal["GL_POINT_TOKEN"] = 0x0701;
		retVal["GL_LINE_TOKEN"] = 0x0702;
		retVal["GL_LINE_RESET_TOKEN"] = 0x0707;
		retVal["GL_POLYGON_TOKEN"] = 0x0703;
		retVal["GL_BITMAP_TOKEN"] = 0x0704;
		retVal["GL_DRAW_PIXEL_TOKEN"] = 0x0705;
		retVal["GL_COPY_PIXEL_TOKEN"] = 0x0706;
		retVal["GL_PASS_THROUGH_TOKEN"] = 0x0700;
		retVal["GL_FEEDBACK_BUFFER_POINTER"] = 0x0DF0;
		retVal["GL_FEEDBACK_BUFFER_SIZE"] = 0x0DF1;
		retVal["GL_FEEDBACK_BUFFER_TYPE"] = 0x0DF2;
		retVal["GL_SELECTION_BUFFER_POINTER"] = 0x0DF3;
		retVal["GL_SELECTION_BUFFER_SIZE"] = 0x0DF4;
		retVal["GL_FOG"] = 0x0B60;
		retVal["GL_FOG_MODE"] = 0x0B65;
		retVal["GL_FOG_DENSITY"] = 0x0B62;
		retVal["GL_FOG_COLOR"] = 0x0B66;
		retVal["GL_FOG_INDEX"] = 0x0B61;
		retVal["GL_FOG_START"] = 0x0B63;
		retVal["GL_FOG_END"] = 0x0B64;
		retVal["GL_LINEAR"] = 0x2601;
		retVal["GL_EXP"] = 0x0800;
		retVal["GL_EXP2"] = 0x0801;
		retVal["GL_LOGIC_OP"] = 0x0BF1;
		retVal["GL_INDEX_LOGIC_OP"] = 0x0BF1;
		retVal["GL_COLOR_LOGIC_OP"] = 0x0BF2;
		retVal["GL_LOGIC_OP_MODE"] = 0x0BF0;
		retVal["GL_CLEAR"] = 0x1500;
		retVal["GL_SET"] = 0x150F;
		retVal["GL_COPY"] = 0x1503;
		retVal["GL_COPY_INVERTED"] = 0x150C;
		retVal["GL_NOOP"] = 0x1505;
		retVal["GL_INVERT"] = 0x150A;
		retVal["GL_AND"] = 0x1501;
		retVal["GL_NAND"] = 0x150E;
		retVal["GL_OR"] = 0x1507;
		retVal["GL_NOR"] = 0x1508;
		retVal["GL_XOR"] = 0x1506;
		retVal["GL_EQUIV"] = 0x1509;
		retVal["GL_AND_REVERSE"] = 0x1502;
		retVal["GL_AND_INVERTED"] = 0x1504;
		retVal["GL_OR_REVERSE"] = 0x150B;
		retVal["GL_OR_INVERTED"] = 0x150D;
		retVal["GL_STENCIL_TEST"] = 0x0B90;
		retVal["GL_STENCIL_WRITEMASK"] = 0x0B98;
		retVal["GL_STENCIL_BITS"] = 0x0D57;
		retVal["GL_STENCIL_FUNC"] = 0x0B92;
		retVal["GL_STENCIL_VALUE_MASK"] = 0x0B93;
		retVal["GL_STENCIL_REF"] = 0x0B97;
		retVal["GL_STENCIL_FAIL"] = 0x0B94;
		retVal["GL_STENCIL_PASS_DEPTH_PASS"] = 0x0B96;
		retVal["GL_STENCIL_PASS_DEPTH_FAIL"] = 0x0B95;
		retVal["GL_STENCIL_CLEAR_VALUE"] = 0x0B91;
		retVal["GL_STENCIL_INDEX"] = 0x1901;
		retVal["GL_KEEP"] = 0x1E00;
		retVal["GL_REPLACE"] = 0x1E01;
		retVal["GL_INCR"] = 0x1E02;
		retVal["GL_DECR"] = 0x1E03;
		retVal["GL_NONE"] = 0x0;
		retVal["GL_LEFT"] = 0x0406;
		retVal["GL_RIGHT"] = 0x0407;
		retVal["GL_FRONT_LEFT"] = 0x0400;
		retVal["GL_FRONT_RIGHT"] = 0x0401;
		retVal["GL_BACK_LEFT"] = 0x0402;
		retVal["GL_BACK_RIGHT"] = 0x0403;
		retVal["GL_AUX0"] = 0x0409;
		retVal["GL_AUX1"] = 0x040A;
		retVal["GL_AUX2"] = 0x040B;
		retVal["GL_AUX3"] = 0x040C;
		retVal["GL_COLOR_INDEX"] = 0x1900;
		retVal["GL_RED"] = 0x1903;
		retVal["GL_GREEN"] = 0x1904;
		retVal["GL_BLUE"] = 0x1905;
		retVal["GL_ALPHA"] = 0x1906;
		retVal["GL_LUMINANCE"] = 0x1909;
		retVal["GL_LUMINANCE_ALPHA"] = 0x190A;
		retVal["GL_ALPHA_BITS"] = 0x0D55;
		retVal["GL_RED_BITS"] = 0x0D52;
		retVal["GL_GREEN_BITS"] = 0x0D53;
		retVal["GL_BLUE_BITS"] = 0x0D54;
		retVal["GL_INDEX_BITS"] = 0x0D51;
		retVal["GL_SUBPIXEL_BITS"] = 0x0D50;
		retVal["GL_AUX_BUFFERS"] = 0x0C00;
		retVal["GL_READ_BUFFER"] = 0x0C02;
		retVal["GL_DRAW_BUFFER"] = 0x0C01;
		retVal["GL_DOUBLEBUFFER"] = 0x0C32;
		retVal["GL_STEREO"] = 0x0C33;
		retVal["GL_BITMAP"] = 0x1A00;
		retVal["GL_COLOR"] = 0x1800;
		retVal["GL_DEPTH"] = 0x1801;
		retVal["GL_STENCIL"] = 0x1802;
		retVal["GL_DITHER"] = 0x0BD0;
		retVal["GL_RGB"] = 0x1907;
		retVal["GL_RGBA"] = 0x1908;
		retVal["GL_MAX_LIST_NESTING"] = 0x0B31;
		retVal["GL_MAX_ATTRIB_STACK_DEPTH"] = 0x0D35;
		retVal["GL_MAX_MODELVIEW_STACK_DEPTH"] = 0x0D36;
		retVal["GL_MAX_NAME_STACK_DEPTH"] = 0x0D37;
		retVal["GL_MAX_PROJECTION_STACK_DEPTH"] = 0x0D38;
		retVal["GL_MAX_TEXTURE_STACK_DEPTH"] = 0x0D39;
		retVal["GL_MAX_EVAL_ORDER"] = 0x0D30;
		retVal["GL_MAX_LIGHTS"] = 0x0D31;
		retVal["GL_MAX_CLIP_PLANES"] = 0x0D32;
		retVal["GL_MAX_TEXTURE_SIZE"] = 0x0D33;
		retVal["GL_MAX_PIXEL_MAP_TABLE"] = 0x0D34;
		retVal["GL_MAX_VIEWPORT_DIMS"] = 0x0D3A;
		retVal["GL_MAX_CLIENT_ATTRIB_STACK_DEPTH"] = 0x0D3B;
		retVal["GL_ATTRIB_STACK_DEPTH"] = 0x0BB0;
		retVal["GL_CLIENT_ATTRIB_STACK_DEPTH"] = 0x0BB1;
		retVal["GL_COLOR_CLEAR_VALUE"] = 0x0C22;
		retVal["GL_COLOR_WRITEMASK"] = 0x0C23;
		retVal["GL_CURRENT_INDEX"] = 0x0B01;
		retVal["GL_CURRENT_COLOR"] = 0x0B00;
		retVal["GL_CURRENT_NORMAL"] = 0x0B02;
		retVal["GL_CURRENT_RASTER_COLOR"] = 0x0B04;
		retVal["GL_CURRENT_RASTER_DISTANCE"] = 0x0B09;
		retVal["GL_CURRENT_RASTER_INDEX"] = 0x0B05;
		retVal["GL_CURRENT_RASTER_POSITION"] = 0x0B07;
		retVal["GL_CURRENT_RASTER_TEXTURE_COORDS"] = 0x0B06;
		retVal["GL_CURRENT_RASTER_POSITION_VALID"] = 0x0B08;
		retVal["GL_CURRENT_TEXTURE_COORDS"] = 0x0B03;
		retVal["GL_INDEX_CLEAR_VALUE"] = 0x0C20;
		retVal["GL_INDEX_MODE"] = 0x0C30;
		retVal["GL_INDEX_WRITEMASK"] = 0x0C21;
		retVal["GL_MODELVIEW_MATRIX"] = 0x0BA6;
		retVal["GL_MODELVIEW_STACK_DEPTH"] = 0x0BA3;
		retVal["GL_NAME_STACK_DEPTH"] = 0x0D70;
		retVal["GL_PROJECTION_MATRIX"] = 0x0BA7;
		retVal["GL_PROJECTION_STACK_DEPTH"] = 0x0BA4;
		retVal["GL_RENDER_MODE"] = 0x0C40;
		retVal["GL_RGBA_MODE"] = 0x0C31;
		retVal["GL_TEXTURE_MATRIX"] = 0x0BA8;
		retVal["GL_TEXTURE_STACK_DEPTH"] = 0x0BA5;
		retVal["GL_VIEWPORT"] = 0x0BA2;
		retVal["GL_AUTO_NORMAL"] = 0x0D80;
		retVal["GL_MAP1_COLOR_4"] = 0x0D90;
		retVal["GL_MAP1_GRID_DOMAIN"] = 0x0DD0;
		retVal["GL_MAP1_GRID_SEGMENTS"] = 0x0DD1;
		retVal["GL_MAP1_INDEX"] = 0x0D91;
		retVal["GL_MAP1_NORMAL"] = 0x0D92;
		retVal["GL_MAP1_TEXTURE_COORD_1"] = 0x0D93;
		retVal["GL_MAP1_TEXTURE_COORD_2"] = 0x0D94;
		retVal["GL_MAP1_TEXTURE_COORD_3"] = 0x0D95;
		retVal["GL_MAP1_TEXTURE_COORD_4"] = 0x0D96;
		retVal["GL_MAP1_VERTEX_3"] = 0x0D97;
		retVal["GL_MAP1_VERTEX_4"] = 0x0D98;
		retVal["GL_MAP2_COLOR_4"] = 0x0DB0;
		retVal["GL_MAP2_GRID_DOMAIN"] = 0x0DD2;
		retVal["GL_MAP2_GRID_SEGMENTS"] = 0x0DD3;
		retVal["GL_MAP2_INDEX"] = 0x0DB1;
		retVal["GL_MAP2_NORMAL"] = 0x0DB2;
		retVal["GL_MAP2_TEXTURE_COORD_1"] = 0x0DB3;
		retVal["GL_MAP2_TEXTURE_COORD_2"] = 0x0DB4;
		retVal["GL_MAP2_TEXTURE_COORD_3"] = 0x0DB5;
		retVal["GL_MAP2_TEXTURE_COORD_4"] = 0x0DB6;
		retVal["GL_MAP2_VERTEX_3"] = 0x0DB7;
		retVal["GL_MAP2_VERTEX_4"] = 0x0DB8;
		retVal["GL_COEFF"] = 0x0A00;
		retVal["GL_DOMAIN"] = 0x0A02;
		retVal["GL_ORDER"] = 0x0A01;
		retVal["GL_FOG_HINT"] = 0x0C54;
		retVal["GL_LINE_SMOOTH_HINT"] = 0x0C52;
		retVal["GL_PERSPECTIVE_CORRECTION_HINT"] = 0x0C50;
		retVal["GL_POINT_SMOOTH_HINT"] = 0x0C51;
		retVal["GL_POLYGON_SMOOTH_HINT"] = 0x0C53;
		retVal["GL_DONT_CARE"] = 0x1100;
		retVal["GL_FASTEST"] = 0x1101;
		retVal["GL_NICEST"] = 0x1102;
		retVal["GL_SCISSOR_TEST"] = 0x0C11;
		retVal["GL_SCISSOR_BOX"] = 0x0C10;
		retVal["GL_MAP_COLOR"] = 0x0D10;
		retVal["GL_MAP_STENCIL"] = 0x0D11;
		retVal["GL_INDEX_SHIFT"] = 0x0D12;
		retVal["GL_INDEX_OFFSET"] = 0x0D13;
		retVal["GL_RED_SCALE"] = 0x0D14;
		retVal["GL_RED_BIAS"] = 0x0D15;
		retVal["GL_GREEN_SCALE"] = 0x0D18;
		retVal["GL_GREEN_BIAS"] = 0x0D19;
		retVal["GL_BLUE_SCALE"] = 0x0D1A;
		retVal["GL_BLUE_BIAS"] = 0x0D1B;
		retVal["GL_ALPHA_SCALE"] = 0x0D1C;
		retVal["GL_ALPHA_BIAS"] = 0x0D1D;
		retVal["GL_DEPTH_SCALE"] = 0x0D1E;
		retVal["GL_DEPTH_BIAS"] = 0x0D1F;
		retVal["GL_PIXEL_MAP_S_TO_S_SIZE"] = 0x0CB1;
		retVal["GL_PIXEL_MAP_I_TO_I_SIZE"] = 0x0CB0;
		retVal["GL_PIXEL_MAP_I_TO_R_SIZE"] = 0x0CB2;
		retVal["GL_PIXEL_MAP_I_TO_G_SIZE"] = 0x0CB3;
		retVal["GL_PIXEL_MAP_I_TO_B_SIZE"] = 0x0CB4;
		retVal["GL_PIXEL_MAP_I_TO_A_SIZE"] = 0x0CB5;
		retVal["GL_PIXEL_MAP_R_TO_R_SIZE"] = 0x0CB6;
		retVal["GL_PIXEL_MAP_G_TO_G_SIZE"] = 0x0CB7;
		retVal["GL_PIXEL_MAP_B_TO_B_SIZE"] = 0x0CB8;
		retVal["GL_PIXEL_MAP_A_TO_A_SIZE"] = 0x0CB9;
		retVal["GL_PIXEL_MAP_S_TO_S"] = 0x0C71;
		retVal["GL_PIXEL_MAP_I_TO_I"] = 0x0C70;
		retVal["GL_PIXEL_MAP_I_TO_R"] = 0x0C72;
		retVal["GL_PIXEL_MAP_I_TO_G"] = 0x0C73;
		retVal["GL_PIXEL_MAP_I_TO_B"] = 0x0C74;
		retVal["GL_PIXEL_MAP_I_TO_A"] = 0x0C75;
		retVal["GL_PIXEL_MAP_R_TO_R"] = 0x0C76;
		retVal["GL_PIXEL_MAP_G_TO_G"] = 0x0C77;
		retVal["GL_PIXEL_MAP_B_TO_B"] = 0x0C78;
		retVal["GL_PIXEL_MAP_A_TO_A"] = 0x0C79;
		retVal["GL_PACK_ALIGNMENT"] = 0x0D05;
		retVal["GL_PACK_LSB_FIRST"] = 0x0D01;
		retVal["GL_PACK_ROW_LENGTH"] = 0x0D02;
		retVal["GL_PACK_SKIP_PIXELS"] = 0x0D04;
		retVal["GL_PACK_SKIP_ROWS"] = 0x0D03;
		retVal["GL_PACK_SWAP_BYTES"] = 0x0D00;
		retVal["GL_UNPACK_ALIGNMENT"] = 0x0CF5;
		retVal["GL_UNPACK_LSB_FIRST"] = 0x0CF1;
		retVal["GL_UNPACK_ROW_LENGTH"] = 0x0CF2;
		retVal["GL_UNPACK_SKIP_PIXELS"] = 0x0CF4;
		retVal["GL_UNPACK_SKIP_ROWS"] = 0x0CF3;
		retVal["GL_UNPACK_SWAP_BYTES"] = 0x0CF0;
		retVal["GL_ZOOM_X"] = 0x0D16;
		retVal["GL_ZOOM_Y"] = 0x0D17;
		retVal["GL_TEXTURE_ENV"] = 0x2300;
		retVal["GL_TEXTURE_ENV_MODE"] = 0x2200;
		retVal["GL_TEXTURE_1D"] = 0x0DE0;
		retVal["GL_TEXTURE_2D"] = 0x0DE1;
		retVal["GL_TEXTURE_WRAP_S"] = 0x2802;
		retVal["GL_TEXTURE_WRAP_T"] = 0x2803;
		retVal["GL_TEXTURE_MAG_FILTER"] = 0x2800;
		retVal["GL_TEXTURE_MIN_FILTER"] = 0x2801;
		retVal["GL_TEXTURE_ENV_COLOR"] = 0x2201;
		retVal["GL_TEXTURE_GEN_S"] = 0x0C60;
		retVal["GL_TEXTURE_GEN_T"] = 0x0C61;
		retVal["GL_TEXTURE_GEN_MODE"] = 0x2500;
		retVal["GL_TEXTURE_BORDER_COLOR"] = 0x1004;
		retVal["GL_TEXTURE_WIDTH"] = 0x1000;
		retVal["GL_TEXTURE_HEIGHT"] = 0x1001;
		retVal["GL_TEXTURE_BORDER"] = 0x1005;
		retVal["GL_TEXTURE_COMPONENTS"] = 0x1003;
		retVal["GL_TEXTURE_RED_SIZE"] = 0x805C;
		retVal["GL_TEXTURE_GREEN_SIZE"] = 0x805D;
		retVal["GL_TEXTURE_BLUE_SIZE"] = 0x805E;
		retVal["GL_TEXTURE_ALPHA_SIZE"] = 0x805F;
		retVal["GL_TEXTURE_LUMINANCE_SIZE"] = 0x8060;
		retVal["GL_TEXTURE_INTENSITY_SIZE"] = 0x8061;
		retVal["GL_NEAREST_MIPMAP_NEAREST"] = 0x2700;
		retVal["GL_NEAREST_MIPMAP_LINEAR"] = 0x2702;
		retVal["GL_LINEAR_MIPMAP_NEAREST"] = 0x2701;
		retVal["GL_LINEAR_MIPMAP_LINEAR"] = 0x2703;
		retVal["GL_OBJECT_LINEAR"] = 0x2401;
		retVal["GL_OBJECT_PLANE"] = 0x2501;
		retVal["GL_EYE_LINEAR"] = 0x2400;
		retVal["GL_EYE_PLANE"] = 0x2502;
		retVal["GL_SPHERE_MAP"] = 0x2402;
		retVal["GL_DECAL"] = 0x2101;
		retVal["GL_MODULATE"] = 0x2100;
		retVal["GL_NEAREST"] = 0x2600;
		retVal["GL_REPEAT"] = 0x2901;
		retVal["GL_CLAMP"] = 0x2900;
		retVal["GL_S"] = 0x2000;
		retVal["GL_T"] = 0x2001;
		retVal["GL_R"] = 0x2002;
		retVal["GL_Q"] = 0x2003;
		retVal["GL_TEXTURE_GEN_R"] = 0x0C62;
		retVal["GL_TEXTURE_GEN_Q"] = 0x0C63;
		retVal["GL_VENDOR"] = 0x1F00;
		retVal["GL_RENDERER"] = 0x1F01;
		retVal["GL_VERSION"] = 0x1F02;
		retVal["GL_EXTENSIONS"] = 0x1F03;
		retVal["GL_NO_ERROR"] = 0x0;
		retVal["GL_INVALID_VALUE"] = 0x0501;
		retVal["GL_INVALID_ENUM"] = 0x0500;
		retVal["GL_INVALID_OPERATION"] = 0x0502;
		retVal["GL_STACK_OVERFLOW"] = 0x0503;
		retVal["GL_STACK_UNDERFLOW"] = 0x0504;
		retVal["GL_OUT_OF_MEMORY"] = 0x0505;
		retVal["GL_CURRENT_BIT"] = 0x00000001;
		retVal["GL_POINT_BIT"] = 0x00000002;
		retVal["GL_LINE_BIT"] = 0x00000004;
		retVal["GL_POLYGON_BIT"] = 0x00000008;
		retVal["GL_POLYGON_STIPPLE_BIT"] = 0x00000010;
		retVal["GL_PIXEL_MODE_BIT"] = 0x00000020;
		retVal["GL_LIGHTING_BIT"] = 0x00000040;
		retVal["GL_FOG_BIT"] = 0x00000080;
		retVal["GL_DEPTH_BUFFER_BIT"] = 0x00000100;
		retVal["GL_ACCUM_BUFFER_BIT"] = 0x00000200;
		retVal["GL_STENCIL_BUFFER_BIT"] = 0x00000400;
		retVal["GL_VIEWPORT_BIT"] = 0x00000800;
		retVal["GL_TRANSFORM_BIT"] = 0x00001000;
		retVal["GL_ENABLE_BIT"] = 0x00002000;
		retVal["GL_COLOR_BUFFER_BIT"] = 0x00004000;
		retVal["GL_HINT_BIT"] = 0x00008000;
		retVal["GL_EVAL_BIT"] = 0x00010000;
		retVal["GL_LIST_BIT"] = 0x00020000;
		retVal["GL_TEXTURE_BIT"] = 0x00040000;
		retVal["GL_SCISSOR_BIT"] = 0x00080000;
		retVal["GL_ALL_ATTRIB_BITS"] = 0x000FFFFF;
		retVal["GL_PROXY_TEXTURE_1D"] = 0x8063;
		retVal["GL_PROXY_TEXTURE_2D"] = 0x8064;
		retVal["GL_TEXTURE_PRIORITY"] = 0x8066;
		retVal["GL_TEXTURE_RESIDENT"] = 0x8067;
		retVal["GL_TEXTURE_BINDING_1D"] = 0x8068;
		retVal["GL_TEXTURE_BINDING_2D"] = 0x8069;
		retVal["GL_TEXTURE_INTERNAL_FORMAT"] = 0x1003;
		retVal["GL_ALPHA4"] = 0x803B;
		retVal["GL_ALPHA8"] = 0x803C;
		retVal["GL_ALPHA12"] = 0x803D;
		retVal["GL_ALPHA16"] = 0x803E;
		retVal["GL_LUMINANCE4"] = 0x803F;
		retVal["GL_LUMINANCE8"] = 0x8040;
		retVal["GL_LUMINANCE12"] = 0x8041;
		retVal["GL_LUMINANCE16"] = 0x8042;
		retVal["GL_LUMINANCE4_ALPHA4"] = 0x8043;
		retVal["GL_LUMINANCE6_ALPHA2"] = 0x8044;
		retVal["GL_LUMINANCE8_ALPHA8"] = 0x8045;
		retVal["GL_LUMINANCE12_ALPHA4"] = 0x8046;
		retVal["GL_LUMINANCE12_ALPHA12"] = 0x8047;
		retVal["GL_LUMINANCE16_ALPHA16"] = 0x8048;
		retVal["GL_INTENSITY"] = 0x8049;
		retVal["GL_INTENSITY4"] = 0x804A;
		retVal["GL_INTENSITY8"] = 0x804B;
		retVal["GL_INTENSITY12"] = 0x804C;
		retVal["GL_INTENSITY16"] = 0x804D;
		retVal["GL_R3_G3_B2"] = 0x2A10;
		retVal["GL_RGB4"] = 0x804F;
		retVal["GL_RGB5"] = 0x8050;
		retVal["GL_RGB8"] = 0x8051;
		retVal["GL_RGB10"] = 0x8052;
		retVal["GL_RGB12"] = 0x8053;
		retVal["GL_RGB16"] = 0x8054;
		retVal["GL_RGBA2"] = 0x8055;
		retVal["GL_RGBA4"] = 0x8056;
		retVal["GL_RGB5_A1"] = 0x8057;
		retVal["GL_RGBA8"] = 0x8058;
		retVal["GL_RGB10_A2"] = 0x8059;
		retVal["GL_RGBA12"] = 0x805A;
		retVal["GL_RGBA16"] = 0x805B;
		retVal["GL_CLIENT_PIXEL_STORE_BIT"] = 0x00000001;
		retVal["GL_CLIENT_VERTEX_ARRAY_BIT"] = 0x00000002;
		retVal["GL_ALL_CLIENT_ATTRIB_BITS"] = 0xFFFFFFFF;
		retVal["GL_CLIENT_ALL_ATTRIB_BITS"] = 0xFFFFFFFF;
		retVal["GL_RESCALE_NORMAL"] = 0x803A;
		retVal["GL_CLAMP_TO_EDGE"] = 0x812F;
		retVal["GL_MAX_ELEMENTS_VERTICES"] = 0x80E8;
		retVal["GL_MAX_ELEMENTS_INDICES"] = 0x80E9;
		retVal["GL_BGR"] = 0x80E0;
		retVal["GL_BGRA"] = 0x80E1;
		retVal["GL_UNSIGNED_BYTE_3_3_2"] = 0x8032;
		retVal["GL_UNSIGNED_BYTE_2_3_3_REV"] = 0x8362;
		retVal["GL_UNSIGNED_SHORT_5_6_5"] = 0x8363;
		retVal["GL_UNSIGNED_SHORT_5_6_5_REV"] = 0x8364;
		retVal["GL_UNSIGNED_SHORT_4_4_4_4"] = 0x8033;
		retVal["GL_UNSIGNED_SHORT_4_4_4_4_REV"] = 0x8365;
		retVal["GL_UNSIGNED_SHORT_5_5_5_1"] = 0x8034;
		retVal["GL_UNSIGNED_SHORT_1_5_5_5_REV"] = 0x8366;
		retVal["GL_UNSIGNED_INT_8_8_8_8"] = 0x8035;
		retVal["GL_UNSIGNED_INT_8_8_8_8_REV"] = 0x8367;
		retVal["GL_UNSIGNED_INT_10_10_10_2"] = 0x8036;
		retVal["GL_UNSIGNED_INT_2_10_10_10_REV"] = 0x8368;
		retVal["GL_LIGHT_MODEL_COLOR_CONTROL"] = 0x81F8;
		retVal["GL_SINGLE_COLOR"] = 0x81F9;
		retVal["GL_SEPARATE_SPECULAR_COLOR"] = 0x81FA;
		retVal["GL_TEXTURE_MIN_LOD"] = 0x813A;
		retVal["GL_TEXTURE_MAX_LOD"] = 0x813B;
		retVal["GL_TEXTURE_BASE_LEVEL"] = 0x813C;
		retVal["GL_TEXTURE_MAX_LEVEL"] = 0x813D;
		retVal["GL_SMOOTH_POINT_SIZE_RANGE"] = 0x0B12;
		retVal["GL_SMOOTH_POINT_SIZE_GRANULARITY"] = 0x0B13;
		retVal["GL_SMOOTH_LINE_WIDTH_RANGE"] = 0x0B22;
		retVal["GL_SMOOTH_LINE_WIDTH_GRANULARITY"] = 0x0B23;
		retVal["GL_ALIASED_POINT_SIZE_RANGE"] = 0x846D;
		retVal["GL_ALIASED_LINE_WIDTH_RANGE"] = 0x846E;
		retVal["GL_PACK_SKIP_IMAGES"] = 0x806B;
		retVal["GL_PACK_IMAGE_HEIGHT"] = 0x806C;
		retVal["GL_UNPACK_SKIP_IMAGES"] = 0x806D;
		retVal["GL_UNPACK_IMAGE_HEIGHT"] = 0x806E;
		retVal["GL_TEXTURE_3D"] = 0x806F;
		retVal["GL_PROXY_TEXTURE_3D"] = 0x8070;
		retVal["GL_TEXTURE_DEPTH"] = 0x8071;
		retVal["GL_TEXTURE_WRAP_R"] = 0x8072;
		retVal["GL_MAX_3D_TEXTURE_SIZE"] = 0x8073;
		retVal["GL_TEXTURE_BINDING_3D"] = 0x806A;
		retVal["GL_COLOR_TABLE"] = 0x80D0;
		retVal["GL_POST_CONVOLUTION_COLOR_TABLE"] = 0x80D1;
		retVal["GL_POST_COLOR_MATRIX_COLOR_TABLE"] = 0x80D2;
		retVal["GL_PROXY_COLOR_TABLE"] = 0x80D3;
		retVal["GL_PROXY_POST_CONVOLUTION_COLOR_TABLE"] = 0x80D4;
		retVal["GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE"] = 0x80D5;
		retVal["GL_COLOR_TABLE_SCALE"] = 0x80D6;
		retVal["GL_COLOR_TABLE_BIAS"] = 0x80D7;
		retVal["GL_COLOR_TABLE_FORMAT"] = 0x80D8;
		retVal["GL_COLOR_TABLE_WIDTH"] = 0x80D9;
		retVal["GL_COLOR_TABLE_RED_SIZE"] = 0x80DA;
		retVal["GL_COLOR_TABLE_GREEN_SIZE"] = 0x80DB;
		retVal["GL_COLOR_TABLE_BLUE_SIZE"] = 0x80DC;
		retVal["GL_COLOR_TABLE_ALPHA_SIZE"] = 0x80DD;
		retVal["GL_COLOR_TABLE_LUMINANCE_SIZE"] = 0x80DE;
		retVal["GL_COLOR_TABLE_INTENSITY_SIZE"] = 0x80DF;
		retVal["GL_CONVOLUTION_1D"] = 0x8010;
		retVal["GL_CONVOLUTION_2D"] = 0x8011;
		retVal["GL_SEPARABLE_2D"] = 0x8012;
		retVal["GL_CONVOLUTION_BORDER_MODE"] = 0x8013;
		retVal["GL_CONVOLUTION_FILTER_SCALE"] = 0x8014;
		retVal["GL_CONVOLUTION_FILTER_BIAS"] = 0x8015;
		retVal["GL_REDUCE"] = 0x8016;
		retVal["GL_CONVOLUTION_FORMAT"] = 0x8017;
		retVal["GL_CONVOLUTION_WIDTH"] = 0x8018;
		retVal["GL_CONVOLUTION_HEIGHT"] = 0x8019;
		retVal["GL_MAX_CONVOLUTION_WIDTH"] = 0x801A;
		retVal["GL_MAX_CONVOLUTION_HEIGHT"] = 0x801B;
		retVal["GL_POST_CONVOLUTION_RED_SCALE"] = 0x801C;
		retVal["GL_POST_CONVOLUTION_GREEN_SCALE"] = 0x801D;
		retVal["GL_POST_CONVOLUTION_BLUE_SCALE"] = 0x801E;
		retVal["GL_POST_CONVOLUTION_ALPHA_SCALE"] = 0x801F;
		retVal["GL_POST_CONVOLUTION_RED_BIAS"] = 0x8020;
		retVal["GL_POST_CONVOLUTION_GREEN_BIAS"] = 0x8021;
		retVal["GL_POST_CONVOLUTION_BLUE_BIAS"] = 0x8022;
		retVal["GL_POST_CONVOLUTION_ALPHA_BIAS"] = 0x8023;
		retVal["GL_CONSTANT_BORDER"] = 0x8151;
		retVal["GL_REPLICATE_BORDER"] = 0x8153;
		retVal["GL_CONVOLUTION_BORDER_COLOR"] = 0x8154;
		retVal["GL_COLOR_MATRIX"] = 0x80B1;
		retVal["GL_COLOR_MATRIX_STACK_DEPTH"] = 0x80B2;
		retVal["GL_MAX_COLOR_MATRIX_STACK_DEPTH"] = 0x80B3;
		retVal["GL_POST_COLOR_MATRIX_RED_SCALE"] = 0x80B4;
		retVal["GL_POST_COLOR_MATRIX_GREEN_SCALE"] = 0x80B5;
		retVal["GL_POST_COLOR_MATRIX_BLUE_SCALE"] = 0x80B6;
		retVal["GL_POST_COLOR_MATRIX_ALPHA_SCALE"] = 0x80B7;
		retVal["GL_POST_COLOR_MATRIX_RED_BIAS"] = 0x80B8;
		retVal["GL_POST_COLOR_MATRIX_GREEN_BIAS"] = 0x80B9;
		retVal["GL_POST_COLOR_MATRIX_BLUE_BIAS"] = 0x80BA;
		retVal["GL_POST_COLOR_MATRIX_ALPHA_BIAS"] = 0x80BB;
		retVal["GL_HISTOGRAM"] = 0x8024;
		retVal["GL_PROXY_HISTOGRAM"] = 0x8025;
		retVal["GL_HISTOGRAM_WIDTH"] = 0x8026;
		retVal["GL_HISTOGRAM_FORMAT"] = 0x8027;
		retVal["GL_HISTOGRAM_RED_SIZE"] = 0x8028;
		retVal["GL_HISTOGRAM_GREEN_SIZE"] = 0x8029;
		retVal["GL_HISTOGRAM_BLUE_SIZE"] = 0x802A;
		retVal["GL_HISTOGRAM_ALPHA_SIZE"] = 0x802B;
		retVal["GL_HISTOGRAM_LUMINANCE_SIZE"] = 0x802C;
		retVal["GL_HISTOGRAM_SINK"] = 0x802D;
		retVal["GL_MINMAX"] = 0x802E;
		retVal["GL_MINMAX_FORMAT"] = 0x802F;
		retVal["GL_MINMAX_SINK"] = 0x8030;
		retVal["GL_TABLE_TOO_LARGE"] = 0x8031;
		retVal["GL_BLEND_EQUATION"] = 0x8009;
		retVal["GL_MIN"] = 0x8007;
		retVal["GL_MAX"] = 0x8008;
		retVal["GL_FUNC_ADD"] = 0x8006;
		retVal["GL_FUNC_SUBTRACT"] = 0x800A;
		retVal["GL_FUNC_REVERSE_SUBTRACT"] = 0x800B;
		retVal["GL_BLEND_COLOR"] = 0x8005;
		retVal["GL_TEXTURE0"] = 0x84C0;
		retVal["GL_TEXTURE1"] = 0x84C1;
		retVal["GL_TEXTURE2"] = 0x84C2;
		retVal["GL_TEXTURE3"] = 0x84C3;
		retVal["GL_TEXTURE4"] = 0x84C4;
		retVal["GL_TEXTURE5"] = 0x84C5;
		retVal["GL_TEXTURE6"] = 0x84C6;
		retVal["GL_TEXTURE7"] = 0x84C7;
		retVal["GL_TEXTURE8"] = 0x84C8;
		retVal["GL_TEXTURE9"] = 0x84C9;
		retVal["GL_TEXTURE10"] = 0x84CA;
		retVal["GL_TEXTURE11"] = 0x84CB;
		retVal["GL_TEXTURE12"] = 0x84CC;
		retVal["GL_TEXTURE13"] = 0x84CD;
		retVal["GL_TEXTURE14"] = 0x84CE;
		retVal["GL_TEXTURE15"] = 0x84CF;
		retVal["GL_TEXTURE16"] = 0x84D0;
		retVal["GL_TEXTURE17"] = 0x84D1;
		retVal["GL_TEXTURE18"] = 0x84D2;
		retVal["GL_TEXTURE19"] = 0x84D3;
		retVal["GL_TEXTURE20"] = 0x84D4;
		retVal["GL_TEXTURE21"] = 0x84D5;
		retVal["GL_TEXTURE22"] = 0x84D6;
		retVal["GL_TEXTURE23"] = 0x84D7;
		retVal["GL_TEXTURE24"] = 0x84D8;
		retVal["GL_TEXTURE25"] = 0x84D9;
		retVal["GL_TEXTURE26"] = 0x84DA;
		retVal["GL_TEXTURE27"] = 0x84DB;
		retVal["GL_TEXTURE28"] = 0x84DC;
		retVal["GL_TEXTURE29"] = 0x84DD;
		retVal["GL_TEXTURE30"] = 0x84DE;
		retVal["GL_TEXTURE31"] = 0x84DF;
		retVal["GL_ACTIVE_TEXTURE"] = 0x84E0;
		retVal["GL_CLIENT_ACTIVE_TEXTURE"] = 0x84E1;
		retVal["GL_MAX_TEXTURE_UNITS"] = 0x84E2;
		retVal["GL_NORMAL_MAP"] = 0x8511;
		retVal["GL_REFLECTION_MAP"] = 0x8512;
		retVal["GL_TEXTURE_CUBE_MAP"] = 0x8513;
		retVal["GL_TEXTURE_BINDING_CUBE_MAP"] = 0x8514;
		retVal["GL_TEXTURE_CUBE_MAP_POSITIVE_X"] = 0x8515;
		retVal["GL_TEXTURE_CUBE_MAP_NEGATIVE_X"] = 0x8516;
		retVal["GL_TEXTURE_CUBE_MAP_POSITIVE_Y"] = 0x8517;
		retVal["GL_TEXTURE_CUBE_MAP_NEGATIVE_Y"] = 0x8518;
		retVal["GL_TEXTURE_CUBE_MAP_POSITIVE_Z"] = 0x8519;
		retVal["GL_TEXTURE_CUBE_MAP_NEGATIVE_Z"] = 0x851A;
		retVal["GL_PROXY_TEXTURE_CUBE_MAP"] = 0x851B;
		retVal["GL_MAX_CUBE_MAP_TEXTURE_SIZE"] = 0x851C;
		retVal["GL_COMPRESSED_ALPHA"] = 0x84E9;
		retVal["GL_COMPRESSED_LUMINANCE"] = 0x84EA;
		retVal["GL_COMPRESSED_LUMINANCE_ALPHA"] = 0x84EB;
		retVal["GL_COMPRESSED_INTENSITY"] = 0x84EC;
		retVal["GL_COMPRESSED_RGB"] = 0x84ED;
		retVal["GL_COMPRESSED_RGBA"] = 0x84EE;
		retVal["GL_TEXTURE_COMPRESSION_HINT"] = 0x84EF;
		retVal["GL_TEXTURE_COMPRESSED_IMAGE_SIZE"] = 0x86A0;
		retVal["GL_TEXTURE_COMPRESSED"] = 0x86A1;
		retVal["GL_NUM_COMPRESSED_TEXTURE_FORMATS"] = 0x86A2;
		retVal["GL_COMPRESSED_TEXTURE_FORMATS"] = 0x86A3;
		retVal["GL_MULTISAMPLE"] = 0x809D;
		retVal["GL_SAMPLE_ALPHA_TO_COVERAGE"] = 0x809E;
		retVal["GL_SAMPLE_ALPHA_TO_ONE"] = 0x809F;
		retVal["GL_SAMPLE_COVERAGE"] = 0x80A0;
		retVal["GL_SAMPLE_BUFFERS"] = 0x80A8;
		retVal["GL_SAMPLES"] = 0x80A9;
		retVal["GL_SAMPLE_COVERAGE_VALUE"] = 0x80AA;
		retVal["GL_SAMPLE_COVERAGE_INVERT"] = 0x80AB;
		retVal["GL_MULTISAMPLE_BIT"] = 0x20000000;
		retVal["GL_TRANSPOSE_MODELVIEW_MATRIX"] = 0x84E3;
		retVal["GL_TRANSPOSE_PROJECTION_MATRIX"] = 0x84E4;
		retVal["GL_TRANSPOSE_TEXTURE_MATRIX"] = 0x84E5;
		retVal["GL_TRANSPOSE_COLOR_MATRIX"] = 0x84E6;
		retVal["GL_COMBINE"] = 0x8570;
		retVal["GL_COMBINE_RGB"] = 0x8571;
		retVal["GL_COMBINE_ALPHA"] = 0x8572;
		retVal["GL_SOURCE0_RGB"] = 0x8580;
		retVal["GL_SOURCE1_RGB"] = 0x8581;
		retVal["GL_SOURCE2_RGB"] = 0x8582;
		retVal["GL_SOURCE0_ALPHA"] = 0x8588;
		retVal["GL_SOURCE1_ALPHA"] = 0x8589;
		retVal["GL_SOURCE2_ALPHA"] = 0x858A;
		retVal["GL_OPERAND0_RGB"] = 0x8590;
		retVal["GL_OPERAND1_RGB"] = 0x8591;
		retVal["GL_OPERAND2_RGB"] = 0x8592;
		retVal["GL_OPERAND0_ALPHA"] = 0x8598;
		retVal["GL_OPERAND1_ALPHA"] = 0x8599;
		retVal["GL_OPERAND2_ALPHA"] = 0x859A;
		retVal["GL_RGB_SCALE"] = 0x8573;
		retVal["GL_ADD_SIGNED"] = 0x8574;
		retVal["GL_INTERPOLATE"] = 0x8575;
		retVal["GL_SUBTRACT"] = 0x84E7;
		retVal["GL_CONSTANT"] = 0x8576;
		retVal["GL_PRIMARY_COLOR"] = 0x8577;
		retVal["GL_PREVIOUS"] = 0x8578;
		retVal["GL_DOT3_RGB"] = 0x86AE;
		retVal["GL_DOT3_RGBA"] = 0x86AF;
		retVal["GL_CLAMP_TO_BORDER"] = 0x812D;

		retVal["GL_VERTEX_SHADER"] = GL_VERTEX_SHADER;
		retVal["GL_FRAGMENT_SHADER"] = GL_FRAGMENT_SHADER;
		retVal["GL_GEOMETRY_SHADER"] = GL_GEOMETRY_SHADER;
	}

	return retVal[c];
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::ColorMask(const glm::ivec4& mask)
{
	if (mask != _colorMask)
	{
		_colorMask = mask;
		glColorMask(_colorMask.r == 1, _colorMask.g == 1, _colorMask.b == 1, _colorMask.a == 1);
	}
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::ColorMask(GLboolean val)
{
	if (_colorMask.x != val || _colorMask.y != val || _colorMask.z != val || _colorMask.w != val)
	{
		_colorMask = glm::vec4(val, val, val, val);
		glColorMask(val, val, val, val);
	}
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::Viewport(float x, float y, float width, float height)
{
	if (glm::vec4(x, y, width, height) != _viewport)
	{
		_viewport = glm::vec4(x, y, width, height);
		glViewport(x, y, width, height);
	}
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::Viewport(const glm::vec4& viewport)
{
	if (viewport != _viewport)
	{
		_viewport = viewport;
		glViewport(_viewport.x, _viewport.y, _viewport.z, _viewport.w);
	}
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::DrawFullscreenQuad()
{
	InitializeFullscreenQuadVao();

	ROpenGL::BindVertexArray(_fullscreenQuadVao);
	ROpenGL::DrawVertexArray();
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::FreeCommonWrapper()
{
	ROpenGL::DeleteVertexArray(&_fullscreenQuadVao);
	ROpenGL::DeleteVertexArray(&_primitiveContainerVao);
	ROpenGL::DeleteVertexArray(&_cubeVao);
	ROpenGL::DeleteVertexArray(&_smallSphereVao);
	ROpenGL::DeleteVertexArray(&_largeSphereVao);
	ROpenGL::DeleteVertexArray(&_quadVao);

	ROpenGL::DeleteBuffer(&_primitiveContainer);
}

/*--------------------------------------------------------------------------*/

BasicVertex* CommonWrapper::MapPrimitiveContainer(uint vertexCount)
{
	AssertLogC(vertexCount > ROPENGL_PRIMITIVECONTAINER_SIZE, "Too high number of vertices requested!");

	InitializePrimitiveContainerVao();
	return (BasicVertex*) ROpenGL::GetShadowBuffer(_primitiveContainer, sizeof(BasicVertex) * vertexCount, 0);
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::UnmapPrimitiveContainer()
{
	ROpenGL::FlushShadowBuffer(_primitiveContainer);
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::DrawPrimitive(GLenum topology, uint vertices)
{
	InitializePrimitiveContainerVao();
	AssertLogC(_primitiveContainer->mapped == true, "PrimitiveContainer is still mapped!");

	_primitiveContainerVao->topology = topology;
	_primitiveContainerVao->verticesCount = vertices;

	ROpenGL::BindVertexArray(_primitiveContainerVao);
	ROpenGL::DrawVertexArray();
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializeFullscreenQuadVao()
{
	if (_fullscreenQuadVao == NULL)
	{
		GLVertexBuffer* vb = ROpenGL::GenBuffer("ROPENGL_FULLSCREENQUAD_VBO", EVertexDeclaration::Position0, 4);
		glm::vec3* v = (glm::vec3*) ROpenGL::MapBuffer(vb);
		v[0] = glm::vec3(-1.0f, -1.0f, 0.0f);
		v[1] = glm::vec3(1.0f, -1.0f, 0.0f);
		v[2] = glm::vec3(1.0f, 1.0f, 0.0f);
		v[3] = glm::vec3(-1.0f, 1.0f, 0.0f);
		ROpenGL::UnmapBuffer(vb);

		GLVertexBuffer* ib = ROpenGL::GenBuffer("ROPENGL_FULLSCREENQUAD_IBO", EVertexDeclaration::Indices, 6);
		uint* i = (uint*) ROpenGL::MapBuffer(ib);
		i[0] = 0;
		i[1] = 1;
		i[2] = 2;
		i[3] = 0;
		i[4] = 2;
		i[5] = 3;
		ROpenGL::UnmapBuffer(ib);

		ROpenGL::UnbindBuffers();

		_fullscreenQuadVao = ROpenGL::GenVertexArray("ROPENGL_FULLSCREENQUAD_VAO", GL_TRIANGLES, 6);
		ROpenGL::BindVertexArray(_fullscreenQuadVao, true);

		ROpenGL::AttachBuffer(vb);
		ROpenGL::AttachBuffer(ib);

		ROpenGL::UnbindVertexArray();
		ROpenGL::UnbindBuffers();

		ROpenGL::UniqueBufferOwner(_fullscreenQuadVao, vb);
		ROpenGL::UniqueBufferOwner(_fullscreenQuadVao, ib);
	}
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializePrimitiveContainerVao()
{
	if (_primitiveContainerVao == NULL)
	{
		_primitiveContainer = ROpenGL::GenBuffer("ROPENGL_PRIMITIVECONTAINER_VBO", EVertexDeclaration::BasicVertex, ROPENGL_PRIMITIVECONTAINER_SIZE);
		BasicVertex* v = (BasicVertex*) ROpenGL::MapBuffer(_primitiveContainer);

		for (uint i = 0; i < ROPENGL_PRIMITIVECONTAINER_SIZE; ++i)
		{
			v[i] = BasicVertex();
		}

		ROpenGL::UnmapBuffer(_primitiveContainer);
		ROpenGL::UnbindBuffers();

		_primitiveContainerVao = ROpenGL::GenVertexArray("ROPENGL_PRIMITIVECONTAINER_VAO", GL_TRIANGLES, 3);
		ROpenGL::BindVertexArray(_primitiveContainerVao, true);

		ROpenGL::AttachBuffer(_primitiveContainer);

		ROpenGL::UnbindVertexArray();
		ROpenGL::UnbindBuffers();
	}
}

/*--------------------------------------------------------------------------*/

GLVertexArray* CommonWrapper::GetQuadVao()
{
	if (!_quadVao)
	{
		InitializeQuadVao();
	}

	return _quadVao;
}

/*--------------------------------------------------------------------------*/

GLVertexArray* CommonWrapper::GetCubeVao()
{
	if (!_cubeVao)
	{
		InitializeCubeVao();
	}

	return _cubeVao;
}

/*--------------------------------------------------------------------------*/

GLVertexArray* CommonWrapper::GetLargeSphereVao()
{
	if (!_largeSphereVao)
	{
		InitializeLargeSphere();
	}

	return _largeSphereVao;
}

/*--------------------------------------------------------------------------*/

GLVertexArray* CommonWrapper::GetSmallSphereVao()
{
	if (!_smallSphereVao)
	{
		InitializeSmallSphere();
	}

	return _smallSphereVao;
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializeCubeVao()
{
	GLVertexBuffer* vb_pos = ROpenGL::GenBuffer("CUBEVB_POS", EVertexDeclaration::Position0, 8, GL_STATIC_DRAW);
	glm::vec3* v_pos = (glm::vec3*) ROpenGL::MapBuffer(vb_pos);
	v_pos[0] = glm::vec3(-1.0f, -1.0f, -1.0f);
	v_pos[1] = glm::vec3(-1.0f, -1.0f, 1.0f);
	v_pos[2] = glm::vec3(-1.0f, 1.0f, -1.0f);
	v_pos[3] = glm::vec3(-1.0f, 1.0f, 1.0f);
	v_pos[4] = glm::vec3(1.0f, -1.0f, -1.0f);
	v_pos[5] = glm::vec3(1.0f, -1.0f, 1.0f);
	v_pos[6] = glm::vec3(1.0f, 1.0f, -1.0f);
	v_pos[7] = glm::vec3(1.0f, 1.0f, 1.0f);
	ROpenGL::UnmapBuffer(vb_pos);

	GLVertexBuffer* vb_nrm = ROpenGL::GenBuffer("CUBEVB_NRM", EVertexDeclaration::Normal0, 8, GL_STATIC_DRAW);
	glm::vec3* v_nrm = (glm::vec3*) ROpenGL::MapBuffer(vb_nrm);
	v_nrm[0] = glm::normalize(glm::vec3(-1.0f, -1.0f, -1.0f));
	v_nrm[1] = glm::normalize(glm::vec3(-1.0f, -1.0f, 1.0f));
	v_nrm[2] = glm::normalize(glm::vec3(-1.0f, 1.0f, -1.0f));
	v_nrm[3] = glm::normalize(glm::vec3(-1.0f, 1.0f, 1.0f));
	v_nrm[4] = glm::normalize(glm::vec3(1.0f, -1.0f, -1.0f));
	v_nrm[5] = glm::normalize(glm::vec3(1.0f, -1.0f, 1.0f));
	v_nrm[6] = glm::normalize(glm::vec3(1.0f, 1.0f, -1.0f));
	v_nrm[7] = glm::normalize(glm::vec3(1.0f, 1.0f, 1.0f));
	ROpenGL::UnmapBuffer(vb_nrm);

	GLVertexBuffer* vb_tex = ROpenGL::GenBuffer("CUBEVB_TX", EVertexDeclaration::Texcoord0, 8, GL_STATIC_DRAW);
	glm::vec2* v_tex = (glm::vec2*) ROpenGL::MapBuffer(vb_tex);
	v_tex[0] = glm::vec2(0.0f, 0.0f);
	v_tex[1] = glm::vec2(1.0f, 1.0f);
	v_tex[2] = glm::vec2(1.0f, 0.0f);
	v_tex[3] = glm::vec2(0.0f, 1.0f);
	v_tex[4] = glm::vec2(0.0f, 1.0f);
	v_tex[5] = glm::vec2(1.0f, 0.0f);
	v_tex[6] = glm::vec2(1.0f, 1.0f);
	v_tex[7] = glm::vec2(0.0f, 0.0f);
	ROpenGL::UnmapBuffer(vb_tex);

	GLVertexBuffer* vb_ind = ROpenGL::GenBuffer("CUBEIB", EVertexDeclaration::Indices, 36, GL_STATIC_DRAW);
	uint* v_ind = (uint*) ROpenGL::MapBuffer(vb_ind);
	v_ind[0] = 4;
	v_ind[1] = 0;
	v_ind[2] = 2;
	v_ind[3] = 4;
	v_ind[4] = 2;
	v_ind[5] = 6;
	v_ind[6] = 7;
	v_ind[7] = 3;
	v_ind[8] = 1;
	v_ind[9] = 7;
	v_ind[10] = 1;
	v_ind[11] = 5;
	v_ind[12] = 2;
	v_ind[13] = 0;
	v_ind[14] = 1;
	v_ind[15] = 2;
	v_ind[16] = 1;
	v_ind[17] = 3;
	v_ind[18] = 7;
	v_ind[19] = 5;
	v_ind[20] = 4;
	v_ind[21] = 7;
	v_ind[22] = 4;
	v_ind[23] = 6;
	v_ind[24] = 5;
	v_ind[25] = 1;
	v_ind[26] = 0;
	v_ind[27] = 5;
	v_ind[28] = 0;
	v_ind[29] = 4;
	v_ind[30] = 6;
	v_ind[31] = 2;
	v_ind[32] = 3;
	v_ind[33] = 6;
	v_ind[34] = 3;
	v_ind[35] = 7;

	ROpenGL::UnmapBuffer(vb_ind);
	ROpenGL::UnbindBuffers();

	_cubeVao = ROpenGL::GenVertexArray("CUBEVAO", GL_TRIANGLES, 36);
	ROpenGL::BindVertexArray(_cubeVao);

	ROpenGL::AttachBuffer(vb_pos);
	ROpenGL::AttachBuffer(vb_nrm);
	ROpenGL::AttachBuffer(vb_tex);
	ROpenGL::AttachBuffer(vb_ind);

	ROpenGL::UnbindVertexArray();
	ROpenGL::UnbindBuffers();

	ROpenGL::UniqueBufferOwner(_cubeVao, vb_pos);
	ROpenGL::UniqueBufferOwner(_cubeVao, vb_nrm);
	ROpenGL::UniqueBufferOwner(_cubeVao, vb_tex);
	ROpenGL::UniqueBufferOwner(_cubeVao, vb_ind);
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializeSmallSphere()
{

}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializeLargeSphere()
{
	int height = 0;
	int width = 0;

	for (float y = -glm::pi<float>() * 0.5f; y < glm::pi<float>() * 0.5f + 0.01f; y += glm::pi<float>() * 0.01f)
	{
		++height;
	}

	for (float x = -glm::pi<float>(); x < glm::pi<float>() + 0.01f; x += glm::pi<float>() * 0.01f)
	{
		++width;
	}

	/*--------------------------------------------------------------------------*/

	glm::vec3* verts = new glm::vec3[width * height];
	glm::vec3* normal = new glm::vec3[width * height];
	glm::vec2* texcor = new glm::vec2[width * height];
	uint* indices = new uint[width * height + (width - 1) * (height - 2)];

	int counter = 0;

	for (float y = -glm::pi<float>() * 0.5f; y < glm::pi<float>() * 0.5f + 0.01f; y += glm::pi<float>() * 0.01f)
	{
		for (float x = -glm::pi<float>(); x < glm::pi<float>() + 0.01f; x += glm::pi<float>() * 0.01f)
		{
			verts[counter].x = cosf(y) * cosf(x);
			verts[counter].z = cosf(y) * sinf(x);
			verts[counter].y = sinf(y);

			texcor[counter].x = (y + glm::pi<float>() / 2.0f) / glm::pi<float>();
			texcor[counter].y = (x + glm::pi<float>()) / (2.0f * glm::pi<float>());

			normal[counter] = glm::normalize(verts[counter]);

			++counter;
		}
	}

	int c = 0;

	for (int row = 0; row < height - 1; ++row)
	{
		if ((row % 2) == 0)   // even rows
		{
			for (int col = 0; col < width; ++col)
			{
				indices[c++] = col + row * width;
				indices[c++] = col + (row + 1) * width;
			}
		}
		else   // odd row
		{
			for (int col = width - 1; col > 0; --col)
			{
				indices[c++] = col + (row + 1) * width;
				indices[c++] = col - 1 + row * width;
			}
		}
	}

	if ((height & 1) && height > 2)
	{
		indices[c] = (height - 1) * width;
	}

	GLVertexBuffer* vbpos = ROpenGL::GenBuffer("LSPHEREVB_POS",	EVertexDeclaration::Position0,	height * width);
	GLVertexBuffer* vbnrm = ROpenGL::GenBuffer("LSPHEREVB_NRM", EVertexDeclaration::Normal0,	height * width);
	GLVertexBuffer* vbtex = ROpenGL::GenBuffer("LSPHEREVB_TEX", EVertexDeclaration::Texcoord0,	height * width);
	GLVertexBuffer* vbind = ROpenGL::GenBuffer("LSPHEREVB_IND",	EVertexDeclaration::Indices,	(width * height + (width - 1) * (height - 2)));

	glm::vec3* vbptn = (glm::vec3*) ROpenGL::MapBuffer(vbpos);
	memcpy(vbptn, verts, width * height * sizeof(glm::vec3));
	ROpenGL::UnmapBuffer(vbpos);

	glm::vec3* nrmptn = (glm::vec3*) ROpenGL::MapBuffer(vbnrm);
	memcpy(nrmptn, normal, width * height * sizeof(glm::vec3));
	ROpenGL::UnmapBuffer(vbnrm);

	glm::vec2* tcptn = (glm::vec2*) ROpenGL::MapBuffer(vbtex);
	memcpy(tcptn, texcor, width * height * sizeof(glm::vec2));
	ROpenGL::UnmapBuffer(vbtex);

	uint* ibptn = (uint*) ROpenGL::MapBuffer(vbind);
	memcpy(ibptn, indices, (width * height + (width - 1) * (height - 2)) * sizeof(uint));
	ROpenGL::UnmapBuffer(vbind);

	_largeSphereVao = ROpenGL::GenVertexArray("LSPHEREVAO", GL_TRIANGLE_STRIP, width * height + (width - 1) * (height - 2));
	ROpenGL::BindVertexArray(_largeSphereVao);

	ROpenGL::AttachBuffer(vbpos);
	ROpenGL::AttachBuffer(vbnrm);
	ROpenGL::AttachBuffer(vbtex);
	ROpenGL::AttachBuffer(vbind);

	ROpenGL::UnbindVertexArray();
	ROpenGL::UnbindBuffers();

	ROpenGL::UniqueBufferOwner(_cubeVao, vbpos);
	ROpenGL::UniqueBufferOwner(_cubeVao, vbnrm);
	ROpenGL::UniqueBufferOwner(_cubeVao, vbtex);
	ROpenGL::UniqueBufferOwner(_cubeVao, vbind);

	delete [] verts;
	delete [] texcor;
	delete [] normal;
	delete [] indices;
}

/*--------------------------------------------------------------------------*/

void CommonWrapper::InitializeQuadVao()
{
	GLVertexBuffer* vb = ROpenGL::GenBuffer("QUADVB", EVertexDeclaration::Position0, 4);
	glm::vec3* v = (glm::vec3*) ROpenGL::MapBuffer(vb);
	v[0] = glm::vec3(0.0f, 0.0f, 0.0f);
	v[1] = glm::vec3(1.0f, 0.0f, 0.0f);
	v[2] = glm::vec3(1.0f, 1.0f, 0.0f);
	v[3] = glm::vec3(0.0f, 1.0f, 0.0f);
	ROpenGL::UnmapBuffer(vb);

	GLVertexBuffer* vbtex = ROpenGL::GenBuffer("QUADTEX", EVertexDeclaration::Texcoord0, 4);
	glm::vec3* vt = (glm::vec3*) ROpenGL::MapBuffer(vbtex);
	vt[0] = glm::vec3(0.0f, 0.0f, 0.0f);
	vt[1] = glm::vec3(1.0f, 0.0f, 0.0f);
	vt[2] = glm::vec3(1.0f, 1.0f, 0.0f);
	vt[3] = glm::vec3(0.0f, 1.0f, 0.0f);
	ROpenGL::UnmapBuffer(vbtex);

	GLVertexBuffer* ib = ROpenGL::GenBuffer("QUADIB", EVertexDeclaration::Indices, 6);
	uint* i = (uint*) ROpenGL::MapBuffer(ib);
	i[0] = 0;
	i[1] = 1;
	i[2] = 2;
	i[3] = 0;
	i[4] = 2;
	i[5] = 3;
	ROpenGL::UnmapBuffer(ib);
	ROpenGL::UnbindBuffers();

	_quadVao = ROpenGL::GenVertexArray("QUADVAO", GL_TRIANGLES, 6);
	ROpenGL::BindVertexArray(_quadVao);

	ROpenGL::AttachBuffer(vb);
	ROpenGL::AttachBuffer(vbtex);
	ROpenGL::AttachBuffer(ib);

	ROpenGL::UnbindVertexArray();
	ROpenGL::UnbindBuffers();

	ROpenGL::UniqueBufferOwner(_quadVao, vb);
	ROpenGL::UniqueBufferOwner(_quadVao, ib);
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& buffer, GLUniformBuffer& ubo)
{
	buffer << "---------------------------------------------------------------\n";
	buffer << "Uniform Buffer Object\n";
	buffer << "  Name:           " << ubo.name << "\n";
	buffer << "  Handle:         " << ubo.handle << "\n";
	buffer << "  Size:           " << ubo.size << "\n";
	buffer << "  ItemsCount:     " << ubo.memmap.size() << "\n";
	buffer << "  BindingIndex:   " << ubo.bindingIndex << "\n";
	buffer << "\n";

	buffer << "---Items-------------------------------------------------------\n";
	buffer << "    " << std::setw(6) << "offset" << std::setw(12) << "type" << std::setw(32) << "name" << "\n";

	for (uint i = 0; i < ubo.memmap.size(); ++i)
	{
		auto item = ubo.memmap[i];
		buffer << "    " << std::setw(6) << item.offset << std::setw(12) << EUniformType::ToStr(item.type) << std::setw(32) << item.name << "\n";
	}

	buffer << "---------------------------------------------------------------\n";
	return buffer;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& buffer, GLShader& sh)
{
	buffer << "---------------------------------------------------------------\n";
	buffer << "Shader\n";
	buffer << "  Name:           " << sh.name << "\n";
	buffer << "  Handle:         " << sh.handle << "\n";
	buffer << "  Size:           " << sh.source.size() << "\n";
	buffer << "  UBOs:           " << sh.data_ubo.size() << "\n";
	buffer << "  Inputs:         " << sh.data_inputs.size() << "\n";
	buffer << "  Outputs:        " << sh.data_outputs.size() << "\n";
	buffer << "  Macros:         " << sh.data_macros.size() << "\n";
	buffer << "  Samplers:       " << sh.data_samplers.size() << "\n";
	buffer << "\n";

	buffer << "---Samplers----------------------------------------------------\n";
	buffer << "    " << std::setw(12) << "location" << std::setw(24) << "name" << std::setw(12) << "pointer" << "\n";

	for (uint i = 0; i < sh.data_samplers.size(); ++i)
	{
		auto item = sh.data_samplers[i];
		buffer << "    " << std::setw(12) << item.location << std::setw(24) << item.name << std::setw(12) << item.textureCtn << "\n";
	}

	buffer << "---Macros------------------------------------------------------\n";
	buffer << "    " << std::setw(24) << "name" << std::setw(24) << "value" << "\n";

	for (uint i = 0; i < sh.data_macros.size(); ++i)
	{
		auto item = sh.data_macros[i];
		buffer << "    " << std::setw(24) << item.name << std::setw(24) << item.value << "\n";
	}

	buffer << "---Inputs------------------------------------------------------\n";
	buffer << "    " << std::setw(12) << "type" << std::setw(24) << "name" << std::setw(12) << "location" << "\n";

	for (uint i = 0; i < sh.data_inputs.size(); ++i)
	{
		auto item = sh.data_inputs[i];
		buffer << "    " << std::setw(12) << item.type << std::setw(24) << item.name << std::setw(12) << item.location << "\n";
	}

	buffer << "---Outputs-----------------------------------------------------\n";
	buffer << "    " << std::setw(12) << "type" << std::setw(24) << "name" << std::setw(12) << "location" << "\n";

	for (uint i = 0; i < sh.data_outputs.size(); ++i)
	{
		auto item = sh.data_outputs[i];
		buffer << "    " << std::setw(12) << item.type << std::setw(24) << item.name << std::setw(12) << item.location << "\n";
	}

	buffer << "---Uniform Buffer Objects--------------------------------------\n";
	buffer << "    " << std::setw(24) << "name" << std::setw(12) << "location" << "\n";

	for (uint i = 0; i < sh.data_ubo.size(); ++i)
	{
		auto item = sh.data_ubo[i];
		buffer << "    " << std::setw(24) << item.ubo->name << std::setw(12) << item.blockIndex << "\n";
	}

	buffer << "---Source------------------------------------------------------\n";
	uint size = sh.source.size();
	uint line = 1;

	buffer << std::setw(4) << line++ << " | ";

	for (uint i = 0; i < size ; ++i)
	{
		if (sh.source[i] == '\n')
		{
			buffer << "\n" << std::setw(4) << line++ << " | ";
		}
		else
		{
			buffer << sh.source[i];
		}
	}

	buffer << "\n";

	buffer << "---CompilationLog----------------------------------------------\n";
	buffer << sh.compilationLog << "\n";

	buffer << "---------------------------------------------------------------\n";

	return buffer;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& buffer, GLProgram& pr)
{
	buffer << "---------------------------------------------------------------\n";
	buffer << "Program\n";
	buffer << "  Name:           " << pr.name << "\n";
	buffer << "  Handle:         " << pr.handle << "\n";
	buffer << "  Shaders:        " << pr.attachedShaders.size() << "\n";
	buffer << "  Linked:         " << pr.linked << "\n";
	buffer << "\n";

	buffer << "---Shaders-----------------------------------------------------\n";
	buffer << "    " << std::setw(32) << "name" << std::setw(12) << "type" << "\n";

	for (uint i = 0; i < pr.attachedShaders.size(); ++i)
	{
		auto item = pr.attachedShaders[i];
		buffer << "    " << std::setw(32) << item->name << std::setw(12) << item->type << "\n";
	}

	buffer << "---CompilationLog----------------------------------------------\n";
	buffer << pr.linkLog << "\n";

	buffer << "---------------------------------------------------------------\n";

	return buffer;
}

/*--------------------------------------------------------------------------*/

std::ostream& operator<<(std::ostream& buffer, GLFramebuffer& fbo)
{
	buffer << "---------------------------------------------------------------\n";
	buffer << "Framebuffer\n";
	buffer << "  Name:           " << fbo.name << "\n";
	buffer << "  Handle:         " << fbo.handle << "\n";
	buffer << "  Attachments:    " << fbo.attachments.size() + (fbo.depthAttachment ? 1 : 0) << "\n";
	buffer << "  ValidationOk:   " << fbo.validated << "\n";
	buffer << "\n";

	buffer << "---ColorAttachments--------------------------------------------\n";
	buffer << "    " << std::setw(32) << "name" << std::setw(12) << "width" << std::setw(12) << "height" << "\n";

	if (fbo.attachments.size())
	{
		for (uint i = 0; i < fbo.attachments.size(); ++i)
		{
			auto item = fbo.attachmentsPtn[i];
			buffer << "    " << std::setw(32) << item->name << std::setw(12) << item->size.x << std::setw(12) << item->size.y << "\n";
		}
	}
	else
	{
		buffer << "    not attached\n";
	}


	buffer << "---DepthAttachment---------------------------------------------\n";

	if (fbo.depthAttachment)
	{
		buffer << "    " << std::setw(32)
		       << fbo.depthAttachment->name << std::setw(12)
		       << fbo.depthAttachment->size.x << std::setw(12)
		       << fbo.depthAttachment->size.y << "\n";
	}
	else
	{
		buffer << "    not attached\n";
	}

	buffer << "---------------------------------------------------------------\n";

	return buffer;
}

/*--------------------------------------------------------------------------*/